import sbt.Keys._
import sbt._
import sbtassembly.AssemblyPlugin.autoImport._

// ScalaPb task
PB.protoSources in Compile := Seq(baseDirectory.value / "grpc-api" / "access" / "proto")
unmanagedSourceDirectories in Compile += sourceDirectory.value / "gen" / "scala"
PB.targets in Compile := Seq(
  scalapb.gen(flatPackage = true, singleLineToString = true) -> sourceDirectory.value / "gen" / "scala"
)
cleanFiles += sourceDirectory.value / "gen" / "scala"
lazy val project = Project(
  id = "hta-server",
  base = file("."),
  settings = Defaults.coreDefaultSettings ++ Seq(
    name := "hta-server",
    version := "1.0.1",
    scalaVersion := "2.11.8",
    resolvers ++= Seq(
      "chrisdinn" at "http://chrisdinn.github.io/releases/",
      "SpinGo OSS" at "http://spingo-oss.s3.amazonaws.com/repositories/releases",
      "spray repo" at "http://repo.spray.io"
    ),
    //指定java文件使用UTF-8编码进行编译
    javacOptions ++= Seq("-encoding", "UTF-8"),
    javaOptions ++= Seq("-Xms2048m", "-Xmx2048m"),
    libraryDependencies ++= {
      val akkaVersion = "2.4.9"
      val jacksonVersion = "2.8.3"
      Seq(
        "org.scalatest" %% "scalatest" % "2.2.1" % "test",
        "com.typesafe.akka" %% "akka-actor" % akkaVersion,
        "com.typesafe.akka" %% "akka-remote" % akkaVersion,
        "com.typesafe.akka" %% "akka-cluster" % akkaVersion,
        "com.typesafe.akka" %% "akka-cluster-sharding" % akkaVersion,
        "com.typesafe.akka" %% "akka-persistence" % akkaVersion,
        "com.typesafe.akka" %% "akka-slf4j" % akkaVersion,
        "com.typesafe.slick" %% "slick" % "3.2.0-M1",
        "com.typesafe.slick" %% "slick-hikaricp" % "3.2.0-M1",
        "com.fasterxml.jackson.core" % "jackson-core" % jacksonVersion,
        "com.fasterxml.jackson.core" % "jackson-annotations" % jacksonVersion,
        "com.fasterxml.jackson.core" % "jackson-databind" % jacksonVersion,
        "com.fasterxml.jackson.module" %% "jackson-module-scala" % jacksonVersion,
        "ch.qos.logback" % "logback-classic" % "1.1.3",
        "mysql" % "mysql-connector-java" % "5.1.38",
        "org.apache.httpcomponents" % "httpclient" % "4.4",
        "org.jdom" % "jdom" % "1.1",
        "io.spray" %% "spray-json" % "1.3.2",
        "com.typesafe.play" %% "play-json" % "2.4.4",
        "com.datastax.cassandra" % "cassandra-driver-core" % "3.1.0",
        // ScalaPB/Protobuf相关的依赖库
        // ScalaPB & gRPC runtime library
        "io.grpc" % "grpc-netty" % "1.5.0",
        "io.grpc" % "grpc-stub" % "1.5.0",
        "com.trueaccord.scalapb" %% "scalapb-runtime" % com.trueaccord.scalapb.compiler.Version.scalapbVersion % "protobuf",
        "com.trueaccord.scalapb" %% "scalapb-runtime-grpc" % com.trueaccord.scalapb.compiler.Version.scalapbVersion,
        "joda-time" % "joda-time" % "2.9.9"
      )
    },
    test in assembly := {},
    mainClass in assembly := Some("com.yicheng.statistics.HtaServer"),
    assemblyMergeStrategy in assembly := {
      case PathList(ps @ _*) if ps.last endsWith ".properties" => MergeStrategy.first
      case x =>
        val oldStrategy = (assemblyMergeStrategy in assembly).value
        oldStrategy(x)
    },
    assemblyOutputPath in assembly := file(s"./release/${name.value}-${version.value}.jar")
  )
)